<?php


namespace app\admin\model;

class ProjectsOrder extends Base
{
    /**
     * Desc: 获取项目订单进度
     * User: 苏鹏
     * Date: 2023/10/20
     * Time: 14:23
     * @return void
     */
    public function getProjectsOrderSchedule(int $id):string
    {
        //查询订单下部件的完成状态，计算完成度
        $where = [
            'projects_order_id' => $id,
            'status' => 1
        ];
        $finish_count = Component::where($where)->where('component_status', '=', 3)->count();
        $total_count = Component::where($where)->count();
        if(!empty($total_count))
        {
            $schedule = $finish_count/$total_count*100;
            $schedule = round($schedule, 0);
        }else{
            $schedule = 0;
        }
        return $schedule . '%';
    }
}